package hd.cls9;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author oldliu
 * @since 1.0
 */
public class SocketTest {
    /**
     * client
     * Server(ip, port)
     *
     * @param args
     */
    public static void main(String[] args) {
        try {
            ServerSocket st = new ServerSocket(9999);
            System.out.println("启动");
            while (true) {
                Socket s = st.accept();//建立连接
                InputStream in = s.getInputStream();
                OutputStream out = s.getOutputStream();
                System.out.println(s + "连接了");
                int ch;
                while ((ch = in.read()) != -1) {
                    System.out.print((char) ch);
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
